home *** CD-ROM | disk | FTP | other *** search
- /*
- CList.h
- */
-
- #pragma once
-
- #include <LList.h>
- #include <LListIterator.h>
-
- // ------------------------------------------------------------
- // TEMPLATE CLASS CList
-
- template <class T>
- class CList : public LList
- {
- public:
- CList();
-
- T * ItemAt(Int32 inAtIndex) const;
-
- void InsertAt(Uint32 inCount, Int32 inAtIndex, T *inItem);
- void InsertLast(T * inItem);
-
- Int32 IndexOf(const T *inItem) const;
- void RemoveItem(const T *inItem);
- };
-
- // ------------------------------------------------------------
- // TEMPLATE CLASS CListIterator
-
- template <class T>
- class CListIterator
- {
- public:
- CListIterator(CList<T> &inList, Int32 inPosition);
-
- Boolean Current(T * & outItem);
- Boolean Next(T * & outItem);
- Boolean Previous(T * & outItem);
-
- private:
- LListIterator mIterator;
- };
-
- // ----------------------------------------------------------------
-
- template <class T>
- inline CList<T>::CList()
- : LList(sizeof(T *))
- {
- }
-
- template <class T>
- T * CList<T>::ItemAt(Int32 inAtIndex) const
- {
- T * result;
-
- if(FetchItemAt(inAtIndex, &result))
- return result;
- else
- return nil;
- }
-
- template <class T>
- void CList<T>::InsertAt(Uint32 inCount, Int32 inAtIndex, T *inItem)
- {
- InsertItemsAt(inCount, inAtIndex, &inItem);
- }
-
- template <class T>
- void CList<T>::InsertLast(T * inItem)
- {
- InsertItemsAt(1, arrayIndex_Last, &inItem);
- }
-
- template <class T>
- Int32 CList<T>::IndexOf(const T *inItem) const
- {
- return FetchIndexOf(&inItem);
- }
-
- template <class T>
- void CList<T>::RemoveItem(const T *inItem)
- {
- Remove(&inItem);
- }
-
- template <class T>
- inline CListIterator<T>::CListIterator(CList<T> &inList, Int32 inPosition)
- : mIterator(inList, inPosition)
- {}
-
- template <class T>
- inline Boolean CListIterator<T>::Current(T * &outItem)
- {
- return mIterator.Current((void *)&outItem);
- }
-
- template <class T>
- inline Boolean CListIterator<T>::Next(T * &outItem)
- {
- return mIterator.Next((void *)&outItem);
- }
-
- template <class T>
- inline Boolean CListIterator<T>::Previous(T * &outItem)
- {
- return mIterator.Previous((void *)&outItem);
- }
-